<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');


if(!function_exists("_convert"))
{
	function _convert($data)
	{
		$CI =& get_instance();
		if(is_numeric($data))
		{
			$CI->load->model('M_grading_system');
			return $CI->M_grading_system->numeric_to_letter($data);
		}else if($data){

			$CI->load->model('M_grade_smiley');
			$CI->load->helper('url');
			$rs = $CI->M_grade_smiley->get_grade_smiley($data, TRUE);
			if($rs)
			{
				return '<img src="'.image_url($rs->icon).'" width="25">';
			}else{
				return $data;
			}
		}else{
			return "";
		}
	}
}

if(!function_exists("_smiley_dropdown"))
{
	function _smiley_dropdown($selected = false, $def = 'Select', $attr = "", $id = ""){

		$CI =& get_instance();
		$CI->load->model('M_grade_smiley','m');
		$g = $CI->m->get_grade_smiley();
		$s = $CI->m->pull(array('color'=>$selected),'id,name,color,icon');
		$sel = $s ? "<img src='".image_url($s->icon)."' width='25'> &nbsp; ".ucwords($s->name) : $def;
		if($g){
			$r = "
				<div class='btn-group'>
			  <button type='button' class='btn btn-default dropdown-toggle pk_btn_dropdown' data-toggle='dropdown' id=btn_pk_{$id}'>
			  	<span id='btn_pk_text_{$id}'>{$sel}</span>
			    <span class='caret'></span>
			  </button>
			  <ul class='dropdown-menu' role='menu'>";

			if($def){
				$r .= "<li><a {$attr} value='' >{$def}</a></li>";
			}

			foreach ($g as $k => $v) {
				$r .= "<li><a {$attr} value='{$v->color}' ><img src='".image_url($v->icon)."' width='25'> &nbsp; ".ucwords($v->name)."</a></li>";
			}

			$r .= "</ul>
			</div>";
		}

		return $r;
	}
}

if(!function_exists("_smiley"))
{
	function _smiley($color, $def = ''){

		$CI =& get_instance();
		$CI->load->model('M_grade_smiley');
		$rs = $CI->M_grade_smiley->get_grade_smiley($color, true);

		if($rs){
			return "<img src='".image_url($rs->icon)."' width=25 > &nbsp;".ucwords($rs->name);
		}

		return $def;

	/*	switch ($color) {
			case 'yellow':
				$r = "<img src='".image_url('symb-yellow.png')."' width=25 > &nbsp; Hooray";
				break;
			case 'red':
				$r = "<img src='".image_url('symb-red.png')."' width=25 > &nbsp; Great";
				break;
			case 'blue':
				$r = "<img src='".image_url('symb-blue.png')."' width=25 > &nbsp; Nice";
				break;
			case 'green':
				$r = "<img src='".image_url('symb-green.png')."' width=25 > &nbsp; Can Do Better";
				break;
			case 'orange':
				$r = "<img src='".image_url('symb-orange.png')."' width=25 > &nbsp; Help";
				break;
			
			default:
				$r = $def;
				break;
		}

		return $r;*/
	}
}

if(!function_exists("_numeric_badge"))
{
	function _numeric_badge($value = 0)
	{
		$CI =& get_instance();
		$CI->load->helper('url');
		$CI->load->model('M_grading_system');
		return $CI->M_grading_system->get_badge($value);
	}
}